import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class CodeFile {


    public static double getCos(String s1,String s2) throws FileNotFoundException {
        Map<String, Integer> map1=getMap(s1);
        Map<String, Integer> map2=getMap(s2);

        double up=0;
        double a=0,b=0;
        Set<Map.Entry<String, Integer>> entries = map1.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {//遍历map1
            //计算分子
            if(map2.containsKey(entry.getKey()))
                up+=entry.getValue()*map2.get(entry.getKey());
            //计算分母的左半边
            a+=entry.getValue()*entry.getValue();
        }

        Set<Map.Entry<String, Integer>> entries2 = map2.entrySet();
        for (Map.Entry<String, Integer> entry : entries2) {//遍历map2
            //计算分母的左半边
            b+=entry.getValue()*entry.getValue();
        }
        double res=up/(Math.sqrt(a)*Math.sqrt(b));
        return res;
    }

    static Map<String, Integer> getMap(String urlString) throws FileNotFoundException {
        Scanner sc = new Scanner(new File(urlString));
        Map<String,Integer> map=new HashMap<>();
        while(sc.hasNext())
        {
            String str = sc.next();
            if(map.containsKey(str)) {
                Integer integer = map.get(str);//+=1;
                integer+=1;
                map.put(str,integer);
            } else
                map.put(str,1);
        }
        return map;
    }

}